﻿/// <reference path="Pagging.js" />
    function collectdata() {
        var frm = document.forms[0];
        var st = "";
        var sel = document.getElementsByTagName("select");
        for (var i = 0; i < sel.length; i++) {
            st += "&" + sel[i].name + "=" + sel[i].value;
        }
        var sel = document.getElementsByTagName("textarea");
        for (var i = 0; i < sel.length; i++) {
            st += "&" + sel[i].name + "=" + sel[i].value;
        }
        for (var i = 0; i < frm.length; i++) {
            if (frm[i].type == 'text' || frm[i].type == 'password') {
                st += "&" + frm[i].name + "=" + frm[i].value;
            }
            else if (frm[i].type == 'hidden' && frm[i].name == 'hAccessionId') {
                st += "&" + frm[i].name + "=" + frm[i].value;
            }
        }
        return st;
    }

    function ChangeDrop(val, id, tval) {
        if (val != '') { senddata_post('nBookSetup', 'T='+tval+'&id=' + val, id); }
    }
    function get_Accession() {
         var i_val = document.getElementById('TotalQty').value;
         if (i_val != "" && i_val != "0") {
             senddata_post('nBookSetup', 'T=getAccession&val='+i_val, 'Accession');
         }
     }
     function remRow(tbl, val) {
     var ele=document.getElementById(tbl);
     if (parseInt(ele.rows.length) > 2) {
     if (confirm("Are You Sure You Want To delete?") == true) {
             ele.deleteRow(val);
         }
         
             for (var i = 1; i <= ele.rows.length; i++) {
                 if (ele.rows[i]) {
                     ele.rows[i].cells[1].innerHTML = parseInt(i);
                 }
             }
         }
         else {
             alert("You can`t delete this accession no.There shuold be at least one accession no. to add this book.")
         }
     }

     function set_initialVal(maxid) {
        
        var ele = document.getElementById('AccessionTable');
        var _cnt = ele.rows.length;
        var i_val = document.getElementById('TotalQty').value;
        i_val=parseInt(i_val)+1;
        if (parseInt(_cnt) > parseInt(i_val)){
            do {
                ele.deleteRow(parseInt(_cnt) - 1);
                _cnt = parseInt(_cnt) - 1;
            } while (parseInt(_cnt) > parseInt(i_val));
        }
        else {
            var _cnt = ele.rows.length;
            var accessionNo = maxid
            if (i_val != "" && i_val != "0") {
                for (var i = _cnt; i < i_val; i++) {
                    var x = ele.insertRow(i)
                    var cl = new Array();
                    cl[0] = x.insertCell(0);
                    cl[1] = x.insertCell(1);
                    cl[2] = x.insertCell(2);
                    cl[3] = x.insertCell(3);
                    cl[4] = x.insertCell(4);
                    cl[5] = x.insertCell(5);
                    cl[6] = x.insertCell(6);
                    cl[7] = x.insertCell(7);
                    cl[8] = x.insertCell(8);
                    var str = "";
                    str = '<a href="javascript:void(0);" onclick="remRow(\'AccessionTable\',this.parentNode.parentNode.rowIndex);" title="Delete this accession no."><img src=\'images/delete.png\'</a>';
                    cl[0].innerHTML = str;
                    str = '<select title="Riscmb" onblur="chgvalidate(this)" name="cmbbuilding" style="width:120px" id="cmbbuilding' + i + '" onchange="ChangeDrop(this.value,\'cmbfloor' + i + '\',\'changefloor\')">';
                    str += document.getElementById('Defaultbuilding').innerHTML;
                    str += "</select>";
                    str += '<span id="scmbbuilding' + i + '" class="red"></span>'
                    cl[2].innerHTML = str;
                    str = '<select onblur="chgvalidate(this)" title="Riscmb" name="cmbfloor" id="cmbfloor' + i + '" style="width:120px;" onchange="ChangeDrop(this.value,\'cmbroom' + i + '\',\'changeroom\');">'
                    str += document.getElementById('Defaultfloor').innerHTML;
                    str += '</select>';
                    str += '<span id="scmbfloor' + i + '" class="red"></span>'
                    cl[3].innerHTML = str;
                    str = '<select title="Riscmb" onblur="chgvalidate(this)"  name="cmbroom" id="cmbroom' + i + '" style="width:120px" onchange="ChangeDrop(this.value,\'cmbAlmirah' + i + '\',\'changeAlmirah\');">'
                    str += document.getElementById('Defaultroom').innerHTML;
                    str += '</select>';
                    str += '<span id="scmbroom' + i + '" class="red"></span>'
                    cl[4].innerHTML = str;
                    str = '<select title="Riscmb" onblur="chgvalidate(this)" name="cmbAlmirah" id="cmbAlmirah' + i + '"style="width:120px"  onchange="ChangeDrop(this.value,\'cmbsection' + i + '\',\'changeSection\');">'
                    str += document.getElementById('DefaultAlmirah').innerHTML;
                    str += '</select>';
                    str += '<span id="scmbAlmirah' + i + '" class="red"></span>'
                    cl[5].innerHTML = str;
                    str = '<select id="cmbsection' + i + '" name="cmbsection" style="width:120px" title="Riscmb">'
                    str += document.getElementById('DefaultSection').innerHTML;
                    str += '</select>';
                    str += '<span id="scmbsection' + i + '" class="red"></span>'
                    cl[6].innerHTML = str;
                    var _acc = document.getElementById('per').value + accessionNo + document.getElementById('suf').value;
                    str = '<input type="hidden" style="width:120px" name="hAccessionId" id="hAccessionId' + i + '" value="0"/>';
                    str += '<input type="hidden" style="width:120px" name="hAccessionNo" id="hAccessionNo' + i + '" value="' + _acc + '"/>';
                    str += '<input type="text" style="width:120px" name="AccessionNo" id="AccessionNo' + i + '" title="R" onblur="" onchange="checkaccessionno(' + i + ')"  value="' + _acc + '"/>'
                    str += '<span id="sAccessionNo' + i + '" class="red"></span>'
                    cl[7].innerHTML = str;
                    var date = new Date();
                    str = '<input type="text" style="width:120px" name="PurchaseYear" id="PurchaseYear' + i + '" title="R" onblur="" onkeypress="return numbersonly(this,event)"  value="' + date.getFullYear()+'"/>'
                    str += '<span id="sPurchaseYear' + i + '" class="red"></span>'
                    cl[8].innerHTML = str;
                    accessionNo = parseInt(accessionNo) + 1;
                }
            }
            for (var i = 1; i <= ele.rows.length; i++) {
                if (ele.rows[i]) {
                    ele.rows[i].cells[1].innerHTML = parseInt(i);
                }
            }
        }

    }
     function set_Value()
     {
         var eleBuild = document.getElementsByName('cmbbuilding');
        var elefloor = document.getElementsByName('cmbfloor');
        var eleroom = document.getElementsByName('cmbroom');
        var elealmirah = document.getElementsByName('cmbAlmirah');
        var elesection = document.getElementsByName('cmbsection');
        for (var i = 0; i < eleBuild.length; i++) {
            var option = document.getElementById("Defaultbuilding").options;
            eleBuild[i].innerHTML = "";
            for (var j = 0;j < option.length; j++) {
                var opt = Create_Option(option[j].text, option[j].value);
                eleBuild[i].add(opt);
            }
           // eleBuild[i].innerHTML = document.getElementById('Defaultbuilding').innerHTML;
            eleBuild[i].value = document.getElementById('Defaultbuilding').value;
             var option = document.getElementById("Defaultfloor").options;
            elefloor[i].innerHTML = "";
            for (var j = 0; j < option.length; j++) {
                var opt = Create_Option(option[j].text, option[j].value)
                elefloor[i].add(opt);
            }
            elefloor[i].value = document.getElementById('Defaultfloor').value;
            var option = document.getElementById("Defaultroom").options;
            eleroom[i].innerHTML = "";
            for (var j = 0; j < option.length; j++) {
                var opt = Create_Option(option[j].text, option[j].value)
                eleroom[i].add(opt);
            }
            eleroom[i].value = document.getElementById('Defaultroom').value;
            var option = document.getElementById("DefaultAlmirah").options;
            elealmirah[i].innerHTML = "";
            for (var j = 0; j < option.length; j++) {
                var opt = Create_Option(option[j].text, option[j].value)
                elealmirah[i].add(opt);
            }
            elealmirah[i].value = document.getElementById('DefaultAlmirah').value;
            var option = document.getElementById("DefaultSection").options;
            elesection[i].innerHTML = "";
            for (var j = 0; j < option.length; j++) {
                var opt = Create_Option(option[j].text, option[j].value)
                elesection[i].add(opt);
            }
            elesection[i].value = document.getElementById('DefaultSection').value;
        }
    }
    function fillvalue(val) {
        if (val.result.length > 0) {
            if (val.result[0].catiddata.length > 0) {
                for (var i = 0; i < val.result[0].catiddata.length; i++) {
                    if (val.result[0].catiddata[i].grouptype == "Student") {
                        if (val.result[0].catiddata[i].issuable == 'Y') {
                            document.getElementById('StuIssuable').checked = true;
                            document.getElementById('StuIssuable').value = 'Y';
                            document.getElementById('StuDaysToHoldBook').disabled = false;
                            document.getElementById('StuFineCharges').disabled = false;
                            document.getElementById('StuDaysToHoldBook').value = val.result[0].catiddata[i].noofdaystoholdbooks;
                            document.getElementById('StuFineCharges').value = val.result[0].catiddata[i].finecharges;
                            document.getElementById('StuDaysToHoldBook').title = 'RisNo';
                            document.getElementById('StuFineCharges').title = 'RisNo';
                            document.getElementById('txtquantity').value = val.result[0].catiddata[i].quantitytobereserved;
                        } else { resetValue(); }
                    }
                    else if (val.result[0].catiddata[i].grouptype == "Staff") {
                        if (val.result[0].catiddata[i].issuable == 'Y') {
                            document.getElementById('StaffIssuable').checked = true;
                            document.getElementById('StaffIssuable').value = 'Y';
                            document.getElementById('StaffDaysToHoldBook').disabled = false;
                            document.getElementById('StaffFineCharges').disabled = false;
                            document.getElementById('StaffDaysToHoldBook').value = val.result[0].catiddata[i].noofdaystoholdbooks;
                            document.getElementById('StaffFineCharges').value = val.result[0].catiddata[i].finecharges;
                            document.getElementById('StaffDaysToHoldBook').title = 'RisNo';
                            document.getElementById('StaffFineCharges').title = 'RisNo';
                            document.getElementById('txtquantity').value = val.result[0].catiddata[i].quantitytobereserved
                        } else {
                            resetValue();
                        }
                    }
                    else {resetValue();}
                }
            }else{resetValue();}
        }else{resetValue();}

    }
    function search() {
        set_page_Val();
        search_go();
    }
    function resetValue() {
        document.getElementById('StuIssuable').checked = false;
        document.getElementById('StuIssuable').value = 'N';
        document.getElementById('StuDaysToHoldBook').value = '';
        document.getElementById('StuFineCharges').value = '';
        document.getElementById('StuDaysToHoldBook').disabled = true;
        document.getElementById('StuFineCharges').disabled = true;
        document.getElementById('StuDaysToHoldBook').title = '';
        document.getElementById('StuFineCharges').title = '';
        document.getElementById('sStuDaysToHoldBook').innerHTML = '';
        document.getElementById('sStuFineCharges').innerHTML = '';
        document.getElementById('txtquantity').value = 0
        document.getElementById('StaffIssuable').checked = false;
        document.getElementById('StaffIssuable').value = 'N';
        document.getElementById('StaffDaysToHoldBook').value = '';

        document.getElementById('StaffFineCharges').value = '';
        document.getElementById('StaffDaysToHoldBook').disabled = true;
        document.getElementById('StaffFineCharges').disabled = true;
        document.getElementById('StaffDaysToHoldBook').title = '';
        document.getElementById('StaffFineCharges').title = '';
        document.getElementById('sStaffDaysToHoldBook').innerHTML = '';
        document.getElementById('sStaffFineCharges').innerHTML = '';
    }
    function showissub() {
        var subdate = document.getElementById("subdate");
        var sub = document.getElementById("sub");
        if (document.getElementById("chkissub").checked) {
            sub.className = "block";
            subdate.className = "block";
            document.getElementById('txtrdate').title = "RisDate";
        }
        else {
            sub.className = "none";
            subdate.className = "none";
            document.getElementById('txtrdate').title = "";
        }
    }
    function stateChanged() {
        if (xmlhttp.readyState == 4) {
            if (receiveid == "fill") {
                var fill = eval('(' + xmlhttp.responseText + ')')
                fillvalue(fill);
                document.getElementById('serror').innerHTML = "";
            }
            else if (receiveid == "f") {
                // alert(xmlhttp.responseText);
                var fill = eval('(' + xmlhttp.responseText + ')')
                fill_search(fill);
                document.getElementById('serror').innerHTML = "";
            }
            else if (receiveid == "excel") {
                document.getElementById(receiveid).innerHTML = "Download Excel File";
                document.getElementById(receiveid).href = xmlhttp.responseText;
            }
            else if (receiveid == "edit") {
                var fill = eval('(' + xmlhttp.responseText + ')')
                fill_edit(fill);
                document.getElementById('serror').innerHTML = "";
            }
            else if (receiveid == "Accession") {
                set_initialVal(xmlhttp.responseText);
                document.getElementById('serror').innerHTML = "";
            }else  if (xmlhttp.responseText.indexOf("~", 0) > 0) {
                var arr = xmlhttp.responseText.split("~");
                document.getElementById(receiveid).innerHTML = arr[1];
                document.getElementById("id").value = arr[0];
                if (arr[0] == "0") {
                    addcancel();
                    //   document.getElementById("pagedata").innerHTML='';
                } else { btn('editcancel') }
            }
            else {
                //showOfDiv(receiveid);
                if (document.getElementById(receiveid).nodeName.toLowerCase() == "select") {
                    var fill = eval('(' + xmlhttp.responseText + ')')
                    fill_Option(fill, receiveid);
                }
                else {
                document.getElementById(receiveid).innerHTML = xmlhttp.responseText;
                }
            }
            addClass();
        } else {
            if (receiveid == "fill" || receiveid == "Accession" || receiveid == "f" || receiveid == "edit") {
            document.getElementById('serror').innerHTML="<div align='center'><img src='images/loading.gif' /></div>"
        }
        else {
            document.getElementById(receiveid).innerHTML = "<div align='center'><img src='images/loading.gif' /></div>";
        }
        }
}
function fill_Option(val, id) {
    var option = Create_Option("--Select--", "");
    document.getElementById(id).options.add(option);
    if (val.result.length > 0) {
        if (val.result[1]) {
            if (val.result[1].changedfloors) {
                if (val.result[1].changedfloors.length > 0) {
                    for (var i = 0; i < val.result[1].changedfloors.length; i++) {
                        option = Create_Option(val.result[1].changedfloors[i].floorname, val.result[1].changedfloors[i].floorid);
                        document.getElementById(id).options.add(option);
                    }
                }
            }
            else if (val.result[1].changedrooms) {
                if (val.result[1].changedrooms.length > 0) {
                    for (var i = 0; i < val.result[1].changedrooms.length; i++) {
                        option = Create_Option(val.result[1].changedrooms[i].roomname, val.result[1].changedrooms[i].roomid);
                        document.getElementById(id).options.add(option);
                    }
                }
            }
        }
        else {
            if (val.result[0].changedalmirah) {
                if (val.result[0].changedalmirah.length > 0) {
                    for (var i = 0; i < val.result[0].changedalmirah.length; i++) {
                        option = Create_Option(val.result[0].changedalmirah[i].almirahname, val.result[0].changedalmirah[i].almirahid);
                        document.getElementById(id).options.add(option);
                    }
                }
            }
            else if (val.result[0].changedsection) {
                if (val.result[0].changedsection.length > 0) {
                    for (var i = 0; i < val.result[0].changedsection.length; i++) {
                        option = Create_Option(val.result[0].changedsection[i].sectionname, val.result[0].changedsection[i].sectionid);
                        document.getElementById(id).options.add(option);
                    }
                }
            }
        }
    }
}
function Create_Option(text,val) {
    var eleOption = document.createElement('Option')
    eleOption.text = text;
    eleOption.value = val;
    return eleOption; 
}
    function checkaccessionno(val) {
        var accessionid = "AccessionNo" + val;
        var haccessionid = "hAccessionNo" + val;
        var accessionval = document.getElementById(accessionid).value;
        var receivedId = 's' + accessionid;
        if (accessionval != "") {
            senddata_post('nBookSetup', 'T=accession&accessval=' + accessionval, receivedId);
        }
        else {
            document.getElementById(receivedId).innerHTML = "*";
            document.getElementById(accessionid).value = document.getElementById(haccessionid).value;
        }
    }
    function hide(val) {
        if (val == "Y") {
            document.getElementById('mainContent').className = "none";
        }
      else {
          document.getElementById('mainContent').className = "block";
        }
  }
  function search_hide(val) {
          if (val == "N") {
              document.getElementById('content').className = "none";
              document.getElementById('search').className = "block";
              document.getElementById('divbuttons').className = "none"
          }
          else {
              document.getElementById('content').className = "block";
              document.getElementById('search').className = "none";
              document.getElementById('divbuttons').className = "block";
          }
  }
  function showcmbclasvalue(val) {
      document.getElementById("txtcallnumber1").value = val;
  }
  function addcancel() { btn('addcancel'); hide("Y"); search_hide("Y"); addClass(); }
  function add() { hide("N"); btn('add'); ClearValue();get_Accession();}
  function edit()
  {
     
        btn('edit'); document.getElementById('done').className = 'block'; document.getElementById('note').className = 'block'; document.getElementById('TotalQty').disabled = true;
        if (document.getElementById('StuIssuable').value == "N")
        {
          
            document.getElementById('StuFineCharges').disabled = true; document.getElementById('StuDaysToHoldBook').disabled = true;
        }
        if (document.getElementById('StaffIssuable').value == "N")
        {
            document.getElementById('StaffFineCharges').disabled = true; document.getElementById('StaffFineCharges').disabled = true;
        }
        
      
    }
    function editcancel() { btn('editcancel'); document.getElementById('done').className = 'none'; document.getElementById('note').className = 'none'; }
    function save()
    {
        if (validate())
        {
            var stuIssue = "N"
            var staffIssue = "N"
            var subject = [];
            var department = [];
           // var subjectId = document.getElementById("chkSubject").getElementsByTagName('input');
            var subjectId = document.getElementsByName("chksubject");
            for (var i = 0;i< subjectId.length; i++) {
                    if (subjectId[i].checked) {
                        subject.push(subjectId[i].value);
                    }
            }
            var departmentId = document.getElementsByName("chkDepartment");
            for (var i = 0; i < departmentId.length; i++) {
                if (departmentId[i].checked) {
                    department.push(departmentId[i].value);
                }
            }
                      
            
                        //'-----------------------------------------
            if (document.getElementById('StuIssuable').checked)
            {
                stuIssue = "Y";
                
            }
            if (document.getElementById('StaffIssuable').checked) {
                 staffIssue="Y"
             }
             var eleLang = document.getElementById('ddlLanguage')
          
             var lang = "";
             if (eleLang) {
                 if (eleLang.value != "") {
                     lang += "&language=" + eleLang.value;
                 }
             }
             senddata_post('nBookSetup', 'T=BookSetup_save' + collectdata() + '&id=' + document.getElementById("id").value + '&SubjectId='+ subject+ '&DepartmentId=' + department + '&stuIssue=' + stuIssue + '&staffIssue=' + staffIssue + lang, 'serror');
        } 
    }
    function del() { if (confirm("Are You Sure You Want To delete?")) { senddata_post('nBookSetup', 'T=BookSetup_del&id=' + document.getElementById("id").value, 'serror'); } }
    function disable_enable(val1, val2, val3) {
        if (document.getElementById(val1).checked == true) {
            document.getElementById(val1).value = 'Y';
            document.getElementById(val2).value = '';
            document.getElementById(val3).value = '';
            document.getElementById(val2).disabled = false;
            document.getElementById(val3).disabled = false;
            document.getElementById(val2).title = 'RisNo';
            document.getElementById(val3).title = 'RisNo';
        } else {
            document.getElementById(val1).value = 'N';
            document.getElementById(val2).value = '';
            document.getElementById(val3).value = '';
            document.getElementById(val2).disabled = true;
            document.getElementById(val3).disabled = true;
            document.getElementById(val2).title = '';
            document.getElementById(val3).title = '';
            document.getElementById('s' + val2).innerHTML = '';
            document.getElementById('s' + val3).innerHTML = '';
        }
    }
    function DeleteRow() {
        var ele = document.getElementById('AccessionTable');
        var _cnt = ele.rows.length;
        if (parseInt(_cnt) > 1) {
            do {

                ele.deleteRow(_cnt - 1)
                _cnt = parseInt(_cnt) - 1
            } while (_cnt > 1)
        }
    }
    function ClearValue() {
        var txt = document.getElementsByTagName('input')
        var sel = document.getElementsByTagName('select');
        var txta = document.getElementsByTagName('textarea');
        for (var i = 0; i < sel.length; i++) {
            sel[i].value = "";
        }
        for (var i = 0; i < txta.length; i++) {
            txta[i].value = "";
        }
            for (var i = 0; i < txt.length; i++) {
                if (txt[i].type == "text") {
                    txt[i].value = "";
                }
                else if (txt[i].type == "checkbox") {
                    txt[i].checked = false;
                }
            }
            document.getElementById("id").value = 0;
            DeleteRow();
            document.getElementById('TotalQty').value = 1;
          //  get_Accession();
            var date = document.getElementById('server_date').value;
            document.getElementById('BookEntryDate').value = date;
            document.getElementById('billdate').value = date;
            //document.getElementById('txtrdate').value = date;

        }
        function set_page_Val() {
            if (document.getElementById('_currentPage')) {
              document.getElementById('_currentPage').value=1;
          }
        }
        function search_go() {
            var val = document.getElementById("txtfind").value;
             var _currentPage=1;
             var maxRecord=20;
            if (document.getElementById('_currentPage')) {
                _currentPage = document.getElementById('_currentPage').value;
            }
            senddata_post('nBookSetup', 'T=F&q=' + val + '&page=' + _currentPage+'&maxrecord='+maxRecord, 'f');
            search_hide("N");
        }
        function createExecl() {
            if (document.getElementById("excel").innerHTML != "Download Excel File") {
                senddata_post('nBookSetup', 'T=createexcel', 'excel');
                document.getElementById("excel").href = "javascript:void(0)";
            }
            else {
                document.getElementById("excel").innerHTML = "Create Excel File";
            }
        }
        function fill_search(val) {
            var eleSearch = document.getElementById('tblsearch');
            var len = eleSearch.rows.length
            if (len > 1) {
                do {
                    eleSearch.deleteRow(len - 1);
                    len = parseInt(len) - 1;
                } while (len > 1)
            }
            var len = eleSearch.rows.length
            if (val.result.length > 0) {
                if (val.result[0].booksetupsearchdata.length > 0) {
                    for (var i = 0; i < val.result[0].booksetupsearchdata.length; i++) {
                        paging({ "totRecord": "" + val.result[0].booksetupsearchdata[i].maxcount + "", "fnName": "search_go();", "maxShowRecord": "" + val.result[0].booksetupsearchdata[i].maxrecord + "", "noOfLink": "5", "id": ["bPaging", "tPaging"] });
                        if (val.result[0].booksetupsearchdata[i].booktitle) {
                            var x = eleSearch.insertRow(len);
                           // x.setAttribute('onclick', 'senddata_post(\'nBookSetup\',\'T=edit&id=' + val.result[0].booksetupsearchdata[i].bookid + '\',\'edit\')')
                            var cl = new Array();
                            cl[0] = x.insertCell(0);
                            cl[1] = x.insertCell(1);
                            cl[2] = x.insertCell(2);
                            cl[3] = x.insertCell(3);
                            cl[4] = x.insertCell(4);
                            cl[5] = x.insertCell(5);
                            cl[6] = x.insertCell(6);
                            cl[7] = x.insertCell(7);
                            cl[8] = x.insertCell(8);
                            cl[9] = x.insertCell(9);
                            cl[10] = x.insertCell(10);
                            cl[11] = x.insertCell(11);
                            cl[0].innerHTML = val.result[0].booksetupsearchdata[i].cnt;
                            cl[1].innerHTML = val.result[0].booksetupsearchdata[i].categoryname;
                            cl[2].innerHTML = val.result[0].booksetupsearchdata[i].booktitle;
                            cl[3].innerHTML = val.result[0].booksetupsearchdata[i].author1;
                            cl[4].innerHTML = val.result[0].booksetupsearchdata[i].author2;
                            cl[5].innerHTML = val.result[0].booksetupsearchdata[i].author3;
                            cl[6].innerHTML = val.result[0].booksetupsearchdata[i].edition;
                            cl[7].innerHTML = val.result[0].booksetupsearchdata[i].publicationname;
                            cl[8].innerHTML = val.result[0].booksetupsearchdata[i].classification;
                            cl[9].innerHTML = val.result[0].booksetupsearchdata[i].callnumber;
                            cl[10].innerHTML = val.result[0].booksetupsearchdata[i].initialqty;
                            
                            cl[11].innerHTML = "<a href='javascript:void(0)' onclick=\"senddata_post('nBookSetup','T=edit&id=" + val.result[0].booksetupsearchdata[i].bookid + "','edit');\" >Edit</a>";
                            len = parseInt(len) + 1;
                        } else {
                            NoRecordFound(eleSearch)
                         }
                    }
                } else {
                    NoRecordFound(eleSearch)
                }
            } else {
                NoRecordFound(eleSearch)
            }
    }
    function NoRecordFound(eleSearch) {
        var x = eleSearch.insertRow(1);
        var col = x.insertCell(0)
        col.setAttribute("colspan", "11");
        col.setAttribute("style", "text-align:center");
        col.className = "green";
        col.innerHTML = 'No Record Found';
        if (document.getElementById('bPaging')) {
            document.getElementById('bPaging').innerHTML = "";
        }
        if (document.getElementById('bPaging')) {
            document.getElementById('tPaging').innerHTML = "";
        }

    }
    function fill_edit(val)
    {
        //document.getElementById('back_load').innerHTML = "<div align='center'><img src='images/loading.gif' /></div>";
        if (val.result.length > 0) {
            if (val.result[0].booksetupsearchdata.length > 0) {
                for (var i = 0; i < val.result[0].booksetupsearchdata.length; i++) {
                    if (val.result[0].booksetupsearchdata[i].booktitle) {
                        ClearValue();
                        search_hide("Y");
                        hide("N");
                        btn("editcancel");
                        fill_Control("id", val.result[0].booksetupsearchdata[i].bookid)
                        fill_Control("BookTitle", val.result[0].booksetupsearchdata[i].booktitle);
                        fill_Control("cmbcategory", val.result[0].booksetupsearchdata[i].bookcatid);
                        fill_Control("BookEntryDate", val.result[0].booksetupsearchdata[i].cbookentrydate);
                        fill_Control("PublicationName", val.result[0].booksetupsearchdata[i].publicationname);
                        fill_Control("Author1", val.result[0].booksetupsearchdata[i].author1);
                        fill_Control("Author2", val.result[0].booksetupsearchdata[i].author2);
                        fill_Control("Author3", val.result[0].booksetupsearchdata[i].author3);
                        fill_Control("attachments", val.result[0].booksetupsearchdata[i].attachments);
                        fill_Control("Edition", val.result[0].booksetupsearchdata[i].edition);
                        fill_Control("txtVol", val.result[0].booksetupsearchdata[i].bookvol);
                        fill_Control("ISBNNo", val.result[0].booksetupsearchdata[i].isbnno);
                        fill_Control("Description", val.result[0].booksetupsearchdata[i].description);
                        fill_Control("txtquantity", val.result[0].booksetupsearchdata[i].reservedquantity);
                        fill_Control("cmbsupplier", val.result[0].booksetupsearchdata[i].supplierid);
                        fill_Control("txtpyear", val.result[0].booksetupsearchdata[i].publicationyear);
                        fill_Control("cmbclassification", val.result[0].booksetupsearchdata[i].classification);
                        fill_Control("txtcallnumber1", val.result[0].booksetupsearchdata[i].classification);
                        fill_Control("txtcallnumber", val.result[0].booksetupsearchdata[i].callnumber);
                        fill_Control("billno", val.result[0].booksetupsearchdata[i].billno);
                        fill_Control("billdate", val.result[0].booksetupsearchdata[i].cbilldate);
                        fill_Control("Pages", val.result[0].booksetupsearchdata[i].pages);
                        fill_Control("Price", val.result[0].booksetupsearchdata[i].price);
                        fill_Control("StuFineCharges", val.result[0].booksetupsearchdata[i].finechargesforstudent);
                        fill_Control("StuDaysToHoldBook", val.result[0].booksetupsearchdata[i].noofdaystoholdbookforstudent);
                        fill_Control("StaffFineCharges", val.result[0].booksetupsearchdata[i].finechargesforstaff);
                        fill_Control("StaffDaysToHoldBook", val.result[0].booksetupsearchdata[i].noofdaystoholdbookforstaff);
                        fill_Control("TotalQty", val.result[0].booksetupsearchdata[i].initialqty);
                                          if (val.result[0].booksetupsearchdata[i].booklanguage) {
                            fill_Control("ddlLanguage", val.result[0].booksetupsearchdata[i].booklanguage);
                        }
                        if (val.result[0].booksetupsearchdata[i].renewdate) {
                            check("chkissub", "Y");
                            showissub()
                            fill_Control("txtrdate", val.result[0].booksetupsearchdata[i].crenewdate);
                            
                        }
                        else {
                            showissub()
                        }
                        check("StuIssuable", val.result[0].booksetupsearchdata[i].studentissuable);
                        check("StaffIssuable", val.result[0].booksetupsearchdata[i].staffissuable);
                        set_initialVal(val.result[0].booksetupsearchdata[i].initialqty);
                        if (val.result[1].booksetupsearchdata1.length > 0) {
                            for (var j = 0; j < val.result[1].booksetupsearchdata1.length; j++) {
                                var eleBuild = document.getElementsByName('cmbbuilding');
                                var elefloor = document.getElementsByName('cmbfloor');
                                var eleroom = document.getElementsByName('cmbroom');
                                var elealmirah = document.getElementsByName('cmbAlmirah');
                                var elesection = document.getElementsByName('cmbsection');
                                var elehAccession = document.getElementsByName('hAccessionNo');
                                var eleAccession = document.getElementsByName('AccessionNo');
                                var elehAccessionId = document.getElementsByName('hAccessionId');
                                var elePurchaseYear = document.getElementsByName('PurchaseYear');
                                var subject = document.getElementsByName('chkSubject');
                              
                                var eleAnchor = document.getElementById('AccessionTable').getElementsByTagName("a");
                                fill_Control(eleBuild[j].id, val.result[1].booksetupsearchdata1[j].buildingid);
                                var str = "";
                                if (val.result[1].booksetupsearchdata1[j].status) {
                                    if (parseInt(val.result[1].booksetupsearchdata1[j].status) == 1) {
                                        eleAnchor[j].setAttribute('onclick', '');
                                        eleAnchor[j].innerHTML = '';
                                    }
                                }
                                if (val.result[2].booksetupsearchdata2.length > 0) {
                                    for (var k = 0; k < val.result[2].booksetupsearchdata2.length; k++) {
                                       if (parseInt(val.result[2].booksetupsearchdata2[k].buildingid) == parseInt(val.result[1].booksetupsearchdata1[j].buildingid)) {
                                           str+="<option value='"+val.result[2].booksetupsearchdata2[k].floorid+"'>"+val.result[2].booksetupsearchdata2[k].floorname+"</option>'";
                                        }
                                    }
                               }
                               elefloor[j].innerHTML = str;
                               fill_Control(elefloor[j].id, val.result[1].booksetupsearchdata1[j].floorid);
                               str = "";
                               if (val.result[3].booksetupsearchdata3.length > 0) {
                                   for (var k = 0; k < val.result[3].booksetupsearchdata3.length; k++) {
                                       if (parseInt(val.result[3].booksetupsearchdata3[k].floorid) == parseInt(val.result[1].booksetupsearchdata1[j].floorid)) {
                                           str += "<option value='" + val.result[3].booksetupsearchdata3[k].roomid + "'>" + val.result[3].booksetupsearchdata3[k].roomname + "</option>'";
                                       }
                                   }
                               }
                               eleroom[j].innerHTML = str;
                               fill_Control(eleroom[j].id, val.result[1].booksetupsearchdata1[j].roomid);
                               str = "";
                               if (val.result[4].booksetupsearchdata4.length > 0) {
                                   for (var k = 0; k < val.result[4].booksetupsearchdata4.length; k++) {
                                       if (parseInt(val.result[4].booksetupsearchdata4[k].roomid) == parseInt(val.result[1].booksetupsearchdata1[j].roomid)) {
                                           str += "<option value='" + val.result[4].booksetupsearchdata4[k].almirahid + "'>" + val.result[4].booksetupsearchdata4[k].almirahname + "</option>'";
                                       }
                                   }
                               }
                               elealmirah[j].innerHTML = str;
                               fill_Control(elealmirah[j].id, val.result[1].booksetupsearchdata1[j].almirahid);
                               str = "";
                               if (val.result[5].booksetupsearchdata5.length > 0) {
                                   for (var k = 0; k < val.result[5].booksetupsearchdata5.length; k++) {
                                       if (parseInt(val.result[5].booksetupsearchdata5[k].almirahid) == parseInt(val.result[1].booksetupsearchdata1[j].almirahid)) {
                                           str += "<option value='" + val.result[5].booksetupsearchdata5[k].sectionid + "'>" + val.result[5].booksetupsearchdata5[k].sectionname + "</option>'";
                                       }
                                   }
                               }
                             
                                  elesection[j].innerHTML = str;
                                 fill_Control(elesection[j].id,val.result[1].booksetupsearchdata1[j].sectionid);
                                 fill_Control(elehAccession[j].id, val.result[1].booksetupsearchdata1[j].accessionno);
                                 fill_Control(eleAccession[j].id, val.result[1].booksetupsearchdata1[j].accessionno);
                                 fill_Control(elePurchaseYear[j].id, val.result[1].booksetupsearchdata1[j].purchaseyear);
                                 fill_Control(elehAccessionId[j].id, val.result[1].booksetupsearchdata1[j].bookaccessionid);
                                
                            }
                         }

                         btn('editcancel');
                    }
                }
               // fill_Control("chksubject", val.result[1].booksetupsearchdata[j].subjectid);
                var eleSubject = document.getElementsByName("chksubject");
                if (val.result[6].booksetupsearchdata6.length > 0) {
                    for (var k = 0; k < val.result[6].booksetupsearchdata6.length; k++) {
                        for (var l = 0; l < eleSubject.length; l++) {
                            if (val.result[6].booksetupsearchdata6[k].subjectid) {
                                if (eleSubject[l].value == val.result[6].booksetupsearchdata6[k].subjectid) {
                                    eleSubject[l].checked = true;
                                }
                            }
                        }
                    }
                }
                var eleDepartment= document.getElementsByName("chkDepartment");
                if (val.result[7].booksetupsearchdata7.length > 0) {
                    for (var k = 0; k < val.result[7].booksetupsearchdata7.length; k++) {
                        for (var l = 0; l < eleDepartment.length; l++) {
                            if (val.result[7].booksetupsearchdata7[k].groupid) {
                                if (eleDepartment[l].value == val.result[7].booksetupsearchdata7[k].groupid) {
                                    eleDepartment[l].checked = true;
                                }
                            }
                        }
                    }
                }
            }

         }
         //document.getElementById('back_load').innerHTML = "";
     }
    
    function fill_Control(_control, _value) {
        if (document.getElementById(_control)) {
            if (_value) {
                document.getElementById(_control).value = _value;
            }
        }
    }
    function showdata()
    {
        var subject = [];
        var subjectId = document.getElementsByName("chksubject");
        for (var i = 0; i < subjectId.length; i++) {
            if (subjectId[i].checked) {
                subject.push(subjectId[i].value);
               }
        }
        var department = [];
        var departmentId = document.getElementsByName("chkDepartment");
        for (var i = 0; i < departmentId.length; i++) {
            if (departmentId[i].checked) {
                department.push(departmentId[i].value);
           }
        }
       }
    function check(_control, _value) {
        if (document.getElementById(_control)) {
            if (_value == "Y") {
                document.getElementById(_control).checked = true;
            }
        }
    }

    